﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;


using System.ServiceModel;
namespace Thi
{
    public partial class FrmDangNhap : Form
    {
        //public static string mConnect = "Server=.;database=ThiTracNghiem;uid=sa;pwd=123456";
       // public static string mConnect = "Server=.;database=Exam18;uid=sa;pwd=123456";
        //private string msql = "";
        //public DGC_Library  mLibrary;


        svDangNhap.LoginClient sv = new Thi.svDangNhap.LoginClient();
        ServiceHost host = null;

        public FrmDangNhap()
        {
            InitializeComponent();    
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }



        int idDangNhap = 0;
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                if (sv.CheckLogin(textBox1.Text, textBox2.Text))
                {
                    this.Hide();
                    //Thi.Chat.ChatClientForm frm = new Thi.Chat.ChatClientForm(textBox1.Text);
                    FrmChonMonThi f = new FrmChonMonThi(null, textBox1.Text, sv.GetMaNguoiDung(), sv.GetUser(), sv.LoginCauHinhBangDiem(textBox1.Text));
                    f.Show();

                    FrmChatClient g = new FrmChatClient(textBox1.Text);
                    g.Show();
                    //frm.Show();
                }
                else
                {
                    MessageBox.Show("Tên đăng nhập hoặc mật khẩu không đúng", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                txtthongbao.Text = "Kết nối tới sever không thành công"+ex.ToString();
                txtthongbao.ForeColor = Color.Red;
            }
            finally
            {
                if(sv.State!=CommunicationState.Faulted)
                sv.Close();
            }
        }
    }
}
